package de.saarland.uni.lego3d.server;

import de.saarland.uni.lego3d.Lego3D;

/**
 * Handler to treat the incoming messages and cause the right action to be executed.
 */
public class InteractionHandler {

	/** reference to the server **/
	private Server s;

	/**
	 * Creates a new interaction handler.
	 */
	public InteractionHandler(Server server) {
		s = server;
	}

	/**
	 * Causes the Server to send a callback to the Android device, such that the
	 * device knows if the connect message was successfully sent.
	 * 
	 * @param IP
	 */
	public void handleConnectMessage(String IP) {
		s.sendConnectCallback(IP);
	}

	/**
	 * Add a new virtual lego brick to the GUI.
	 * 
	 * @param IP
	 *            - IP of the device, that sent this message
	 * @param legobrick
	 *            - the lego brick to add.
	 */
	public void handleNewBrickMessage(String IP, Legobrick legobrick) {
		if (Lego3D.DEBUG)
			 System.out.println("Android device of IP: " + IP +
					 " sended a new brick. \n"
					 + "LEGO brick: " + legobrick.layoutToString() + legobrick.color);
		Server.gui.setNewBrick(legobrick);
	}

	/**
	 * Set current KinectMessage to the GUI, such that it can react on the changed interaction
	 * @param newKinectAction - the message containing all necessary information to apply the changes in the GUI.
	 */
	public void handleKinectActionMessage(KinectAction newKinectAction) {
		Server.gui.setNewKinectMsg(newKinectAction);
	}
}
